package CezarCipher;

import java.util.Scanner;

public class CezarCipher implements ICipher
{

    private static final char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
        'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    public CezarCipher() {

    }

    @Override
    public String Encrypt(char[] chars, String key) {
        int realKey = Integer.parseInt(key);
        for (int i = 0; i < chars.length; i++) {
            int index = (chars[i] + realKey) % alphabet.length;
            chars[i] = alphabet[index];
        }
        return new String(chars);
    }

    @Override
    public String Decrypt(char[] chars, String key) {
        int realKey = Integer.parseInt(key);
        for (int i = 0; i < chars.length; i++) {
            int index = (chars[i] - realKey);
            index = index >= 0 ? index : (index + alphabet.length);
            chars[i] = alphabet[index];
        }
        return new String(chars);
    }
}
